<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class UserInsertRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return  [
            'userName' => 'required|regex:/^\w{6,20}$/|unique:users,userName',
            'password' => 'required|regex:/^\S{6,20}$/|same:repassword',
            'checkbox' => 'required|accepted:on',
            'email' => 'email|unique:user_detail,email',

        ];
    }

    public function messages()
    {
        return [
            'userName.required'=>'对不起用户名必填',
            'userName.regex'=>'用户名格式不正确',
            'userName.unique'=>'用户名已经存在',
            'password.required' => '密码必填',
            'password.regex' => '密码格式不正确',
            'password.same' => '两次密码不一致',
            'email.email'=>'邮箱格式不正确',
            'email.unique'=>'邮箱已被注册',
            'checkbox.required'=>'请同意微博达人协议'
        ];
    }
}
